<?php 
## include required files
/*******************************/
require_once '../model/email.php'; 
require_once '../model/moduleuser.php';
## Paginaton class
require_once ("../includes/classes/pagination_class.php");
/*******************************/

## Create Objects
/*******************************/
$emailObj	= 	new Model_email();
$moduleObj=new Model_ModuleUser();

if($_GET['q']=='email')
{
	$moduelArray=$moduleObj->getModuleHelpText(7);
	$smarty->assign('moduelArray', $moduelArray);
}

if($_POST['search']!='' && $_POST['search']!='Enter email type or from email') {
	$search = addslashes($_POST['search']);
}
if($_GET["search"]){
	$search = addslashes($_GET['search']);
}
$smarty->assign("search",stripslashes (stripslashes ($search)));
//print_r($_POST);exit;	
##Fetch all email from database
if($_GET['col1'] != '') {
	$col1 = base64_decode($_GET['col1']);
} else {
	$col1 = '0';
}
##  --------- Pagination part first start --------------##
	$result = $emailObj->getAllEmailByValue($search,$col1);	
	if($_GET['col1'] != '') {
		$pageName = "home.php?q=email&col1=".$_GET['col1'].""; 
	} else {
		$pageName = "home.php?q=email"; 	
	}

	if( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != "" ) {
		$pageNum = $_GET[ 'page' ];
	} else {
		$pageNum = 1;
	}
	$smarty->assign('page', $pageNum);
	$rowsPerPage =ROW_PER_PAGE;
	$total_rows = count($result);
	$offset	= ($pageNum - 1) * $rowsPerPage;
	## Count all the records
	$array = $emailObj->getAllEmailByValue($search,$col1,$rowsPerPage, $offset);
	$smarty->assign("array",$array);
##  --------- Pagination part first end --------------##


##  --------- Pagination part second start --------------##
	$newid = $pageNum * $rowsPerPage - $rowsPerPage + 1;
	$smarty-> assign("newid",$newid);
	$class 	= 	"title";
	$other_id = "search=".$search;
	if($total_rows > ROW_PER_PAGE) {
		$pg = new pagination();					// CREATING OBJECT OF THE PAGINATION CLASS
		$pgnation = $pg->pagination_admin($total_rows , $rowsPerPage , $pageNum , $pageName , $other_id, $class);		
		$smarty-> assign("pagination",$pgnation);
	}
##  --------- Pagination part second end --------------##	

	
## Assign session message to smarty variable and unset session variable
if($_SESSION['msg']){
	$smarty->assign("msg", $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Set active class variable for left menu  (main menu and sub menu)
$smarty->assign('activeclass', 'email');
$smarty->assign('mainmenu', '2');

## Unset all the objects created which are on this page
unset($emailObj);
unset($moduleObj);
	
$smarty->display(TEMPLATEDIR_ADMIN . 'emails/email.tpl');
unset($smarty);
?>
